Get first three characters¶
Write a python function to get a string made of its first three characters
of a specified string. If the length of the string is less than 3 then return
the original string.
Sample function and result :
first_three(‘ipy’) -> ipy
first_three(‘python’) -> pyt
def first_three(S):
return S[:3] if len(S) > 3 else S
# test
print(first_three('ipy')) # ipy
print(first_three('python')) # pyt
print(first_three('py')) # py